#ifndef __BSP_TM1650_H
#define __BSP_TM1650_H

#include "ch32f10x.h"
#include "debug.h"


	//	小数点控制引脚设置参数
#define TIMER1_PERIOD			9999    
#define TIMER1_PRESCALER	7199 
#define TIMER1_PULSE			0


#define TM1650_BL 	1	          //亮度等级
#define TM1650_CMD 	0x48				
#define TM1650_NUM1 0x68
#define TM1650_NUM2 0x6A
#define TM1650_NUM3 0x6C
#define TM1650_NUM4 0x6E


#define POINT_LED_RCC			RCC_APB2Periph_GPIOA
#define POINT_LED_PORT  	GPIOA
#define POINT_LED_PIN			GPIO_Pin_10


#define TM1650_RCC					RCC_APB2Periph_GPIOB
#define TM1650_PORT  				GPIOB
#define TM1650_SDA_PIN			GPIO_Pin_9
#define TM1650_CLK_PIN			GPIO_Pin_8


// 小数点控制
#define POINT_LED_ON 					TIM_SetCompare3(TIM1, 0)
#define POINT_LED_OFF 				TIM_SetCompare3(TIM1, TIMER1_PERIOD+1)
#define POINT_LED_TOGGLE 			TIM_SetCompare3(TIM1, (TIMER1_PERIOD+1)/2)


// 数码管通讯端口
#define TM1650_SDA					PBout(9)
#define TM1650_SDA_ON 			GPIO_ResetBits(TM1650_PORT, TM1650_SDA_PIN)
#define TM1650_SDA_OFF 			GPIO_SetBits(TM1650_PORT, TM1650_SDA_PIN)
#define TM1650_SDA_TOGGLE 	PBout(9) ^= (1<<0)

#define TM1650_CLK					PBout(8)
#define TM1650_CLK_ON 			GPIO_ResetBits(TM1650_PORT, TM1650_CLK_PIN)
#define TM1650_CLK_OFF 			GPIO_SetBits(TM1650_PORT, TM1650_CLK_PIN)
#define TM1650_CLK_TOGGLE 	PBout(8) ^= (1<<0)
	
	
void TM1650_Init(void);
void TM1650_SetTime(uint8_t hh,LED_STAT pointStat,uint8_t mm);
void TM1650_UpdataTime(uint8_t hh,LED_STAT stat,uint8_t mm);
void TM1650_UpdataNum(uint16_t num);
void TM1650_UpdataErr(void);
void TM1650_Test(void);
#endif
